<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>循环</title>
	<!--<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>-->
</head>
<body>
<script>
	//求和
	var sum = 0
	for (var i = 0; i <= 100; i++) {
		sum+=i;
	}
	console.log("sum:" + sum);

	//遍历数组
	var arr = ["A","B","C","D"];
	for (let i = 0; i < arr.length; i++) {
		console.log(arr[i]);
	}

	//for(;;){} 无限循环
	var x = 0;
	for(;;) {
		if (x > 100) {
			break;
		}
		x++;
	}
	console.log("x:" + x)

	//for(var ... in ...) {}
	var xiaoming = {
		name:'小明',
		age:20,
		gender:'男'
	}
	for (let prop in xiaoming) {
		console.log(prop);
	}
	for (let x in arr) {
		//其中x代表arr中的array中的索引
		console.log(arr[x]);
	}

	//while
	//计算100以内计数的和
	var sum = 0;
	var i = 99;
	while (i > 0) {
		sum += i;
		i -= 2;
	}
	console.log("100以内奇数和:" + sum);
</script>
</body>
</html>